from tkinter import *
from tkinter import filedialog as fd
import pyAesCrypt
import os


def crypt(filemass):
    password = passField.get()
    bufferSize = 512*1024
    pyAesCrypt.encryptFile(str(filemass[0]), str(filemass[0]) + '.aes', password, bufferSize)
    filemass.clear()



def decrypt(filemass):
    password = passField.get()
    bufferSize = 512*1024
    pyAesCrypt.decryptFile(str(filemass[0]), str(os.path.splitext(filemass[0])[0]), password, bufferSize)
    filemass.clear()


def file_dialog():
    file_name = fd.askopenfilename()
    filemass.append(file_name)


filemass = []

window = Tk()
window.title("Python Cryptographer")
window.geometry('310x250')
window.resizable(width=False, height=False)


label1 = Label(window, text='Enter password:')
label1.place(x = 2, y = 50)

passField = Entry(window, show='*', width='37')
passField.place(x = 2, y = 80)


btn = Button(window, text='Decipher',  command=lambda: decrypt(filemass))
btn.place(x = 210, y = 210)

btn = Button(window, text='Encrypt', command=lambda: crypt(filemass))
btn.place(x = 7, y = 210)


menubar = Menu(window)
filemenu = Menu(menubar, tearoff=0)
filemenu.add_command(label="Open", command=file_dialog)
filemenu.add_separator()
menubar.add_cascade(label="File", menu=filemenu)


window.config(menu=menubar)
window.mainloop()
